//
//  XMnavigationController.m
//  xianshi
//
//  Created by new-1020 on 2016/10/18.
//  Copyright © 2016年 dengchunhua. All rights reserved.
//

#import "XMnavigationController.h"
//#import "MerchantDetailViewController.h"
@interface XMnavigationController ()<UIGestureRecognizerDelegate>

@property (nonatomic , copy) WYBarButtonBlock barButtonBlock;

@end

@implementation XMnavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.barTintColor = XMColor(108, 34, 42);
    self.navigationBar.translucent = NO; //设置导航栏不透明
    NSDictionary *textAttribute = @{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]};
    [[UINavigationBar appearance] setTitleTextAttributes:textAttribute];
//    self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"FZLanTingHeiS-EL-GB" size:18]};
      self.interactivePopGestureRecognizer.delegate = self;
}
// 修改状态栏的颜色
-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//    
//    for (UIViewController * vc in self.childViewControllers) {
////        if ([vc isKindOfClass:[MerchantDetailViewController class]]) {
////            return YES;
////        }
//    }
//    
//    return NO;
//}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) { // 非根控制器
//        // 恢复滑动返回功能 -> 分析:把系统的返回按钮覆盖 -> 1.手势失效(1.手势被清空 2.可能手势代理做了一些事情,导致手势失效)
//        viewController.hidesBottomBarWhenPushed = YES;
//        
//        // 设置返回按钮,只有非根控制器
        viewController.navigationItem.leftBarButtonItem = [self itemWithimage:[UIImage imageNamed:@"icon_back"] selImage:[UIImage imageNamed:@"icon_back"] target:self action:@selector(goback)];
    }
//
//    // 真正在跳转
    [super pushViewController:viewController animated:animated];
}

// 返回的方法
- (void)goback {
    [self popViewControllerAnimated:YES];
}

// 快速创建barButtonItem
- (UIBarButtonItem *)itemWithimage:(UIImage *)image selImage:(UIImage *)selImage target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    //[btn setImage:selImage forState:UIControlStateSelected];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}




@end
